/**
 * 
 */

function isIEBrowser(){
	var userAgent = navigator.userAgent;
	var isOpera = userAgent.indexOf("Opera") > -1;
	if (((userAgent.indexOf("compatible") > -1 && userAgent.indexOf("MSIE") > -1) || userAgent.indexOf("Trident") > -1) && !isOpera) {
		return true;
	}else{
		return false;
	}
}


function checkActiveXObj(){
	var result = true;
	try{
		var locator = new ActiveXObject("WbemScripting.SWbemLocator");
		var service = locator.ConnectServer(".");
	}catch(e){
		result = false;
	}
	return result;
 }


function autoWrite(currentPath){
	try { 
		var pcsystype={
			"0":"未指明的",
			"1":"台式机",
			"2":"笔记本",
			"3":"工作站",
			"4":"企业服务器",
			"5":"SOHO服务器",
			"6":"Appliance PC",
			"7":"性能服务器",
			"8":"Maximum",
		}
		var locator = new ActiveXObject("WbemScripting.SWbemLocator");
		var service = locator.ConnectServer(".");
		var cpu = new Enumerator(service.ExecQuery("SELECT * FROM Win32_Processor")).item();
		var memory = new Enumerator(service.ExecQuery("SELECT * FROM Win32_PhysicalMemory"));
		var system=new Enumerator (service.ExecQuery("SELECT * FROM Win32_ComputerSystem")).item();
		var cs=new Enumerator (service.ExecQuery("SELECT * FROM Win32_ComputerSystemProduct")).item(); 
		var os=new Enumerator (service.ExecQuery("SELECT * FROM Win32_OperatingSystem")).item();
		var disk=new Enumerator (service.ExecQuery("SELECT * FROM Win32_DiskDrive")); 
		var diskSize = Math.ceil(disk.item().Size/1000/1000/1024);
		 
		
		var cpuType = cpu.Name;
		var physicMenCap=Math.ceil(system.TotalPhysicalMemory/1024/1024/1024); 
		var cp=new Enumerator (service.ExecQuery("SELECT * FROM Win32_ComputerSystemProduct")).item();
		var sncode = cs.IdentifyingNumber;
		
		var xh_version = cs.Name;
		var product = cs.Vendor;
		var xh = cs.Version;
		
		$("#form_sn_code").textbox("setValue",sncode);
		$("#form_product").textbox("setValue",product);
		$("#form_productType").textbox("setValue",xh_version);
		$("#form_assets_type").textbox("setValue",xh);
		$("#form_level1").textbox("setValue","电脑");
		$("#form_level2").textbox("setValue",pcsystype[""+system.PCSystemType]);
		$("#ci_os_input").textbox("setValue",os.Caption+" "+os.CSDVersion);
		$("#ci_cpu_input").textbox("setValue",cpuType);

		
		
		var memstr="";
		for(var i = 0; !memory.atEnd(); memory.moveNext(),i++) {
			var index = i+1;
			memstr+="【内存条"+index+"】";
			memstr+="{";
			memstr+="容量:"+memory.item().Capacity/1024/1024/1024+"GB";
			memstr+=",";
			memstr+="厂商:"+memory.item().Manufacturer;
			memstr+=",";
			memstr+="SN号:"+memory.item().SerialNumber;		
			memstr+="}";
		}		
		memstr+="【总内存大小】"+Math.ceil(system.TotalPhysicalMemory/1024/1024/1024)+"GB";

		$("#ci_men_input").textbox("setValue",memstr);

		var diskindex=0;
		var diststr="";
		for(var i = 0; !disk.atEnd(); disk.moveNext(),i++) {						
			var item = disk.item().InterfaceType;						
			var size = Math.ceil(disk.item().Size/1000/1000/1024);
			if(item!="USB"){
				diskindex++;				
				diststr+="【硬盘"+diskindex+"】";
				diststr+="{";
				diststr+="容量:"+size+"GB";
				diststr+=",";
				diststr+="厂商:"+disk.item().Manufacturer;
				diststr+=",";
				diststr+="类型:"+disk.item().InterfaceType;
				diststr+="}";
			}
		}
		$("#ci_hard_input").textbox("setValue",diststr);
		if(sncode.length>=6){
			//var chkStr = sncode.substr(sncode.length-5);
			var url=currentPath+"/getAssetsCodeBySN?snkey="+sncode;
			$.post(url,function(result){
				$("#form_assets_code").textbox("setValue",result);
			});
		} 

	} catch (e) {
	}
	

 }